﻿Imports System
Imports System.Web
Imports System.Reflection

''' <summary>
''' Methods to get assembly information and details.
''' </summary>
Public Class AssemblyUtil

#Region "Private constructor"

	Private Sub New()
		' Can't create instance!
	End Sub

#End Region

#Region "Devv constants"

	''' <summary>
	''' Devv
	''' </summary>
	Public Const COMPANY As String = "Devv"

	''' <summary>
	''' Copyleft 2005-2009, Devv.com
	''' </summary>
	Public Const COPYRIGHT As String = "Copyright 2011, Devv.com"

	''' <summary>
	''' http://devv.com/
	''' </summary>
	Public Const TRADEMARK As String = "http://devv.com/"

#End Region

#Region "Version methods"

	''' <summary>
	''' Gets a friendly assembly version.
	''' </summary>
	''' <returns>Major.Minor.Build version</returns>
	Public Shared Function GetFriendlyVersion(ByVal objAssembly As Assembly) As String

		Dim version As Version = objAssembly.GetName().Version
		Return version.Major & "." & version.Minor & "." & version.Build

	End Function

#End Region

#Region "Application methods"

	''' <summary>
	''' Gets the running application type (Windows Forms or ASP.NET).
	''' </summary>
	''' <returns>AppTypeEnum.AspNet or AppTypeEnum.WindowsForms</returns>
	Public Shared Function GetAppType() As AppTypeEnum

		If Not String.IsNullOrEmpty(HttpRuntime.AppDomainAppId) Then
			Return AppTypeEnum.AspNet
		Else
			Return AppTypeEnum.WindowsForms
		End If

	End Function

#End Region

#Region "Culture methods"

	''' <summary>
	''' Gets the culture language for the current thread
	''' </summary>
	''' <returns>The first 2 letters of the CultureInfo (example: en), lowercased.</returns>
	Public Shared Function GetCurrentCultureLanguage() As String

		Return Threading.Thread.CurrentThread.CurrentUICulture.Name.Substring(0, 2).ToLower()

	End Function

	''' <summary>
	''' Gets the culture region for the current thread
	''' </summary>
	''' <returns>The second 2 letters of the CultureInfo (example: us), lowercased.</returns>
	Public Shared Function GetCurrentCultureRegion() As String

		Dim strCulture As String = Threading.Thread.CurrentThread.CurrentUICulture.Name

		If strCulture.Contains("-") Then
			Return strCulture.Substring(3, 2).ToLower()
		Else
			Return String.Empty
		End If

	End Function

#End Region

End Class